/*
 * @Description: 
 * @Author: spicylemon
 * @Date: 2022-03-02 09:06:05
 * @LastEditors: YWY
 * @LastEditTime: 2022-03-06 21:27:20
 */
import request from '@/api/request.config.js'
//获取文章接口
export const article = (article_id) => {
  return request.get(`/articles/getbyid?article_id=${article_id}`).catch(rej => { console.log(rej) })
}

export const likeAdd = (type, target_id) => {
  return request.post('/likes/add', {
    type,
    target_id
  }).catch(rej => { console.log(rej) })
}

export const likeDelete = (type, target_id) => {
  return request.delete(`/likes/delete?type=${type}&target_id=${target_id}`).catch(rej => { console.log(rej) })
}

export const collectAdd = (article_id) => {
  return request.post('/collections/add', { article_id }).catch((res) => console.log(res));
}

export const collectDelete = (article_id) => {
  return request.delete(`/collections/cancel?article_id=${article_id}`).catch((res) => console.log(res));
}

// export const getComments = (pageNo=1, pageSize=10, id=10) => {
export const getComments = (id) => {
  return request.get(`/comment/queryCommentByArticleId?pageNo=1&pageSize=10&id=${id}`).catch(rej => { console.log(rej) })
}

export const publishComment = (comment_content, article_id) => {
  return request.post('/comment/createComment', {
    comment_content,
    article_id
  }).catch(rej => { console.log(rej) })
}

export const publishReply = (comment_id, comment_reply_id, comment_reply_content, to_user_id) => {
  if (comment_reply_id) {
    return request.post('/commentReply/insertCommentReply', {
      comment_id,
      comment_reply_id,
      comment_reply_content,
      to_user_id
    }).catch(rej => { console.log(rej) })
  } else {
    return request.post('/commentReply/insertCommentReply', {
      comment_id,
      comment_reply_content,
      to_user_id
    }).catch(rej => { console.log(rej) })
  }
}

export const uploads = (file) => {
  return request.post('/articles/uploads', file).catch(rej => { console.log(rej); });
}

export const create = (content, summary, title, partition_id, cover_url) => {
  return request.post('/articles/create', {
    content,
    summary,
    title,
    partition_id,
    cover_url
  }).catch(rej => { console.log(rej); });
}

export const getAllPartition = () => {
  return request.get('/partition/queryAllPartition').catch(rej => { console.log(rej); });
}

//删除文章
export const deleteArticle = (id) => {
  return request.delete(`/articles/delete?article_id=${id}`)
}